package com.example.ljdemo.infrastructure.responce;


import com.example.ljdemo.infrastructure.util.MsgUtils;

/**
 * 自定义的业务异常类,Biz是Business的通用缩写
 *
 * @author jingjing.dong
 * @since 2021/3/21-16:54
 */
public class BizException extends RuntimeException {
    private final ErrorCode errorCode;
    private final Object[] args;

    public BizException(ErrorCode _code, Object[] _args) {
        super("env biz exception", null, false, false);
        this.errorCode = _code;
        this.args = _args;
    }

    public BizException(ErrorCode _code) {
        this(_code, new Object[0]);
    }

    public BizException(ErrorCode _code, String _args) {
        this(_code, new Object[]{_args});
    }

    public BizException(ErrorCode _code, String _args1, String _args2) {
        this(_code, new Object[]{_args1, _args2});
    }

    public BizException(ErrorCode _code, String _args1, String _args2, String _args3) {
        this(_code, new Object[]{_args1, _args2, _args3});
    }

    public String getMessage() {
        return MsgUtils.getMessage(errorCode.name(), args);
    }

    public int getCode() {
        return errorCode.getCode();
    }

    @Override
    public Throwable fillInStackTrace() {
        return this;
    }
}
